package ytl;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import ytl.*;

public class Main_Menu extends WindowAdapter implements ActionListener {
    
    static Systems Systems = new Systems();
    static Finance Finance = new Finance();
    static Inventory Inventory = new Inventory();
    static Sales Sales = new Sales();
    static Main_Menu Menu = new Main_Menu();
    static Error Error = new Error();
    static DBConnection DBConnection = new DBConnection();

    String command = "Main_Menu";

    Box Menu_Data_box = Box.createVerticalBox();
    Box Menu_Data_box2 = Box.createVerticalBox();
        
    protected final static String Inventory_Menu = "Inventory_Menu";
    protected final static String Sales_Menu = "Sales_Menu";
    protected final static String Finance_Menu = "Finance_Menu";
    protected final static String Systems_Menu = "Systems_Menu";
    protected final static String Main_Menu = "Main_Menu";
    public static JFrame frame = new JFrame("YTL General Merchandise Main Menu");

    public JFrame newframe = new JFrame();
 
    final ImageIcon systems_icon = new ImageIcon("pictures/settings_icon.png");
    
    final ImageIcon inventory_button_img = new ImageIcon("pictures/inventory_tracking_button.png");
    final ImageIcon financial_button_img = new ImageIcon("pictures/financial_tracking_button.png");
    final ImageIcon sales_button_img = new ImageIcon("pictures/sales_button.png");
    final ImageIcon return_home_button_img = new ImageIcon("pictures/return_home_button.png");
        
    final ImageIcon inventory_buttonr_img = new ImageIcon("pictures/inventory_tracking_button_r.png");
    final ImageIcon finance_buttonr_img = new ImageIcon("pictures/financial_tracking_button_r.png");
    final ImageIcon sales_buttonr_img = new ImageIcon("pictures/sales_button_r.png");
    final ImageIcon return_home_buttonr_img = new ImageIcon("pictures/return_home_button_r.png");
    
    final ImageIcon inventory_buttonp_img = new ImageIcon("pictures/inventory_tracking_button_p.png");
    final ImageIcon finance_buttonp_img = new ImageIcon("pictures/financial_tracking_button_p.png");
    final ImageIcon sales_buttonp_img = new ImageIcon("pictures/sales_button_p.png");
    final ImageIcon return_home_buttonp_img = new ImageIcon("pictures/return_home_button_p.png");
        
    final static ImageIcon background_img = new ImageIcon("pictures/ytl_logo.jpg");
    final public JButton inventory_button = new JButton(inventory_button_img);
    final public JButton sales_button = new JButton(sales_button_img);
    final public JButton finance_button = new JButton(financial_button_img);
    final public JButton main_menu_button = new JButton(return_home_button_img);
    final public JButton systems_button = new JButton(systems_icon);
    
    JLabel background = new JLabel();
    Dimension D = new Dimension();
    static Dimension Dim = new Dimension();
        
    public static JPanel pane = new JPanel();
    final static Border line = new LineBorder(Color.WHITE);
    final static Border margin = new EmptyBorder(5, 15, 5, 15);
    final static Border compound = new CompoundBorder(line, margin);
    static Container contentPane = new Container();
    // </editor-fold>
        
    public final void frame_template(){
        newframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        newframe.setLocation(frame.getLocation());
        D.setSize(frame.getSize());
        newframe.setSize(D.getSize());
    }
    
    public void Init_Exit_Menu_Button(){
        main_menu_button.setRolloverIcon(return_home_buttonr_img);
        main_menu_button.setPressedIcon(return_home_buttonp_img);
        main_menu_button.setActionCommand(Main_Menu);
        Button_Options(main_menu_button);
        main_menu_button.addActionListener(this);
        
        inventory_button.setRolloverIcon(inventory_buttonr_img);
        inventory_button.setPressedIcon(inventory_buttonp_img);
        inventory_button.setActionCommand(Inventory_Menu);
        Button_Options(inventory_button);
        inventory_button.addActionListener(this);

        sales_button.setRolloverIcon(sales_buttonr_img);
        sales_button.setPressedIcon(sales_buttonp_img);
        sales_button.setActionCommand(Sales_Menu);
        Button_Options(sales_button);
        sales_button.addActionListener(this);

        finance_button.setRolloverIcon(finance_buttonr_img);
        finance_button.setPressedIcon(finance_buttonp_img);
        finance_button.setActionCommand(Finance_Menu);
        Button_Options(finance_button);
        finance_button.addActionListener(this);
        
        systems_button.setActionCommand(Systems_Menu);
        Button_Options(systems_button);
        systems_button.addActionListener(this);
    }

    public JComponent Exit_Menu_Button() {    
        pane.removeAll();
        if(!command.equals("Inventory_Menu"))
        pane.add(inventory_button);
        if(command.equals("Inventory_Menu"))
        pane.add(main_menu_button);
        if(!command.equals("Sales_Menu"))
        pane.add(sales_button);
        if(command.equals("Sales_Menu"))
        pane.add(main_menu_button);
        if(!command.equals("Finance_Menu"))
        pane.add(finance_button);
        if(command.equals("Finance_Menu"))
        pane.add(main_menu_button);
        
        pane.add(systems_button);

        pane.setBackground(Color.GRAY);
        pane.repaint();
        return pane;
    }
    
    public static void Button_Options (JButton Button){
        Button.setBorder(BorderFactory.createEmptyBorder());
        Button.setContentAreaFilled(false);
    }
    
    public static void Button_Options2 (JButton Button){
        Button.setForeground(Color.WHITE);
        Button.setBackground(Color.BLACK);
        Button.setBorder(compound);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        command = e.getActionCommand();

        contentPane = frame.getContentPane();
        contentPane.removeAll();
        pane.removeAll();
        contentPane.setBackground(Color.LIGHT_GRAY);
    
        if (Inventory_Menu.equals(command)) {
            contentPane.add(Inventory.Inventory_Data(),BorderLayout.BEFORE_LINE_BEGINS);
            contentPane.add(Inventory.Inventory_Tables());
            frame.setTitle("YTL General Merchandise Inventory Menu");
        }
        else if (Sales_Menu.equals(command)) {
            contentPane.add(Sales.Sales_Data(),BorderLayout.BEFORE_LINE_BEGINS);
            contentPane.add(Sales.Sales_Tables());
            frame.setTitle("YTL General Merchandise Sales Menu");
        }
        else if (Finance_Menu.equals(command)) {
            contentPane.add(Finance.Finance_Data(),BorderLayout.BEFORE_LINE_BEGINS);
            contentPane.add(Finance.Finance_Text());
            frame.setTitle("YTL General Merchandise Finance Menu");
        }
        else if (Main_Menu.equals(command)) {
            contentPane.add(Menu_Data(),BorderLayout.BEFORE_LINE_BEGINS);
            frame.setTitle("YTL General Merchandise Main Menu");
        }
        else if (Systems_Menu.equals(command)) {
            contentPane.add(Systems.Systems_Menu(),BorderLayout.BEFORE_LINE_BEGINS);
            contentPane.add(Systems.Systems_Data());
            frame.setTitle("YTL General Merchandise System Settings Menu");
        }
        contentPane.add(Exit_Menu_Button(),BorderLayout.PAGE_END);
        frame.getContentPane().validate();
        frame.getContentPane().repaint();
    }
    
    protected JComponent Menu_Data() {
        background.setIcon(background_img);
        Menu_Data_box2.add(background);
        Menu_Data_box.add(Menu_Data_box2);
        return Menu_Data_box;
    }
    
    public static void Main_Menu() {
        contentPane = frame.getContentPane();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        contentPane.setBackground(Color.LIGHT_GRAY);
        contentPane.add(Menu.Menu_Data(),BorderLayout.BEFORE_LINE_BEGINS);
        contentPane.add(Menu.Exit_Menu_Button(),BorderLayout.PAGE_END);
        Menu.Init_Exit_Menu_Button();
        DBConnection.Init_DBC();
        Systems.Init_Systems();
        Sales.Init_Sales();
        Inventory.Init_Inventory();
        Finance.Init_Finance();
        

        frame.pack();
        frame.setLocation(62, 50);
        Dim.setSize(912,500);
        frame.setSize(Dim.getSize());
        frame.setMinimumSize(Dim.getSize());
        frame.setVisible(true);
    }

    public static void main(String[] args) {

        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                Main_Menu();
            }
        });
    }
}